#include<bits/stdc++.h>
#define int long long
using namespace std;
int T;
int a,b,c;
int Pow(int x,int y){
    int z=1;
    while(y){
        if(y&1) z=z*x;
        x=x*x;
        y>>=1;
    }
    return z;
}
void sol(){
    scanf("%lld %lld %lld",&a,&b,&c);
    int ans=0;
    for(int i=1;i<=a;i++){
        for(int j=1;j<=b;j++){
            for(int k=1;k<=c;k++){
                if(Pow(j,i)==Pow(i,k)) ans++;
            }
        }
    }
    printf("%lld\n",ans);
}
signed main(){
    freopen("alien.in","r",stdin);
    freopen("alien.out","w",stdout);
    scanf("%lld",&T);
    while(T--) sol();
    return 0;
}